﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITAP.ShprossesBuilder.Modelling.Components.Constraints
{
    [Serializable]
    public class RemoveUnneccessaryCrossConnectorConstraint : IConstraint
    {
        #region IConstraint Members

        public bool Check(IComponent component)
        {
            return false;
        }

        public void Fix(IComponent component)
        {
            List<IComponent> connectorsToDelete = new List<IComponent>();
            foreach(IComponent innerComponent in component.InnerComponents)
                if (innerComponent is CrossConnector)
                {
                    CrossConnector connector = innerComponent as CrossConnector;
                    if (connector.StartConnectedComponent == null ||
                        connector.EndConnectedComponent == null)
                        connectorsToDelete.Add(connector);
                }

            foreach (IComponent connector in connectorsToDelete)
                component.RemoveInnerComponent(connector);
        }

        private bool enabled = true;
        public bool Enabled
        {
            get
            {
                return enabled;
            }
            set
            {
                enabled = value;
            }
        }

        public ConstraintAction Action
        {
            get { return ConstraintAction.Fix; }
        }

        #endregion

        #region ICloneable Members

        public object Clone()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
